fn main() {
//     1.迭代器可以收集到vector中
    let collected_iterator: Vec<_> = (0..10).collect();
    println!("Collected (0..10) into: {:?}", &collected_iterator);
//     2.`vec!`宏可用来初始化vector
    let mut xs = vec![1i32, 2, 3];
    println!("Initial vector: {:?}", &xs);
//     3.在vector末尾追加元素
    println!("Push 4 into the vector");
    xs.push(4);
    println!("Vector: {:?}", &xs);
//     4.`len`方法获得vector的长度
    println!("Vector length: {}", xs.len());
//     5.`pop`方法移除vector的最后一个元素并将它返回
    println!("Pop last element:{:?}", xs.pop());
//     6.下标使用中括号表示(从0开始)
    println!("Second element: {}", xs[1]);
//     7.下标越界会导致panic
//     println!("Element at index 10: {}", xs[10]);
//     8.可以使用`get`方法来避免下标越界
    println!("Element at index 10: {:?}", xs.get(10));
//     9.迭代一个`vector`很容易
    println!("Contents of xs:");
    for x in xs.iter() {
        println!("> iter: {}", x);
    }
//     10.可以在迭代`vector`同时,记录迭代的次数
    for (i, x) in xs.iter().enumerate(){
        println!("In position {} we have value {}", i + 1, x);
    }
//     11.`iter_mut`让vector迭代时可以修改元素
    for x  in xs.iter_mut(){
        *x *= 3;
    }
    println!("Updated vector: {:?}", &xs);
}
